<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>工勿忧</title>
<link rel="stylesheet" type="text/css" href="../../../css/api.css" />
<link rel="stylesheet" type="text/css" href="../../../css/hui.css" />
<link rel="stylesheet" type="text/css" href="../../../css/iconfont.css" />
</head>

<body>
<style>
.list {
	border: solid #ddd 1px;border-radius: 5px;width: 97%;margin-left: 3%;margin-top: 15px;background-color: aliceblue;
	box-shadow: 3px 3px 3px #ccc;
}

table {}
table tr td { padding: 5px; }
</style>

<div class="hui-wrap" id="record_2">
	<div class="hui-list" style="background:#FFFFFF;margin-top:3px;padding-right:10px;">
		<ul id="list">

		</ul>
	</div>
</div>


<script src="../../../script/hui.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../script/hui-tab.js" type="text/javascript"></script>
<script src="../../../script/api.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../script/stm.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">
	apiready = function () {
		$api.setStorage('curpage',1);
		list(1);
		api.setRefreshHeaderInfo({
			visible : true,
			bgColor : 'rgba(0,0,0,0)',
			textColor : '#666',
			textDown : '下拉刷新',
			textUp : '释放刷新'
		}, function(ret, err) {
			api.refreshHeaderLoadDone();
			list(1);
		});

		api.addEventListener({
			name:'scrolltobottom',
			extra:{
				threshold:0 //设置距离底部多少距离时触发，默认值为0，数字类型
			}
			
		}, function(ret, err){

			$api.setStorage('curpage',parseInt($api.getStorage('curpage'))+1)
			var page = parseInt($api.getStorage('curpage'));
			list(page);

		});




	}


	function list(page) {
		api.showProgress({title: '努力加载中...',text: '先喝杯茶...',modal: false});
		api.ajax({
			url: $api.getStorage('geturl') + '&c=ajaxmember&a=pharmacyrecordajax',
			method: 'post',
			data: {
				values: { 
					userid: $api.getStorage('userid'),
					page  : page
				}
			}
		},function(res, err){

			if (res) {			
				if (res.status==1) {

					//数据上报
					var updata = ''
					for (i = 0; i < res.data.length; i++) {
						//血压,血脂,血糖,慢性肺阻
						updata += '<div class="list"><table style="width:100%">'
						updata += '<tr><td style="font-size:16px;color:#f00;">取药时间：' + res.data[i].addtime + '</td></tr>'
						for (i2 = 0; i2 < res.data[i].drug.length; i2++) {
							updata += '<tr><td>'+(i2+1)+'、' + res.data[i].drug[i2].drugname + '</td><td style="width:70px">数量 ' + res.data[i].drug[i2].num + '</td></tr>';
						}						
						updata += '</table></div>'
					}
					if(updata==''){
						api.toast({ msg:'没有更多数据了',location:'top' })
					}
					$api.append($api.byId("list"),updata);
					
				}else{
					api.toast({ msg:res.tip,location:'top' })
				}
			} else {
				alert( JSON.stringify( err ) );
			}
		}); 
		api.hideProgress();

		
	}


	hui('#hui-header-menu').click(function () {
		hui.actionSheet(menus, cancel, function (e) {
			console.log(e.index);
			hui.toast(e.innerHTML);
		});
	});

/*
	function tip() {
		hui.prompt('您确认要这处理吗？', ['取消', '确定'], function (name) {
			hui.toast('您输入了 :' + name);
		},
			'例如 : 张三',
			'已联系本人处理',
			function () {
				hui.toast('您点击了取消')
			});
	}*/

	/*function tab(i) {
		if (i == 1) {
			hui("#record_1").show();
			hui("#record_2").hide();
			var UILineChart = api.require('UILineChart');
			UILineChart.open();
		} else {
			var UILineChart = api.require('UILineChart');
			UILineChart.close();
			hui("#record_1").hide();
			hui("#record_2").show();
		}
	}*/

</script>

</body>

</html>